package com.component.api.excepiton;

/**
 * 描述：
 * 组件出错统一异常
 * @author xianggj
 * @Date 2021/9/2 17:35
 **/
public class ComponentException extends RuntimeException {

    private Throwable throwable;

    public ComponentException(String msg) {
        super(msg);
    }


    public ComponentException(String msg, Throwable throwable) {
        super(msg);
        this.throwable = throwable;
    }

    @Override
    public String getMessage() {
        if (throwable == null){
            return super.getMessage();
        } else {
            return deepException(throwable);
        }
    }

    private String deepException(Throwable t) {
        if (t.getCause() == null) {
            return t.getMessage();
        }
        return deepException(t.getCause());
    }
}
